<template>
<!-- 车位管理 -->
    <!-- 数据表格 -->
    <div class="datalists">
        <div class="datalistsname">数据列表</div>
        <!-- 添加按钮 -->
        <el-button type="primary" class="append" @click="append"><i class="el-icon-plus"></i>添加车位</el-button>
        <!-- 批量添加 -->
        <el-button type="primary" class="appends" @click="appends">导入数据</el-button>
        <!-- 数据表格 -->
        <div class="datatable">
            <el-table
            :data="tableData"
            border
            stripe
            style="width: 100%">
                <el-table-column
                type="index"
                label="序号"
                width="50">
                </el-table-column>
                <el-table-column
                prop="Belongingcommunity"
                label="所属小区"
                width="145">
                </el-table-column>
                <el-table-column
                prop="GargeName"
                label="车库名称"
                width="145">
                </el-table-column>
                <el-table-column
                prop="GargeErea"
                label="车位区域"
                width="145">
                </el-table-column>
                <el-table-column
                prop="ParkinglotNumber"
                label="车位号"
                width="145">
                </el-table-column>
                <el-table-column
                prop="Housingstatus"
                label="车位状态"
                width="145">
                </el-table-column>
                <el-table-column
                prop="ParkinglotErea"
                label="车位面积"
                width="145">
                </el-table-column>
                <el-table-column
                prop="ParkinglotNote"
                label="备注"
                width="111">
                </el-table-column>
                <el-table-column
                prop="operate"
                label="操作"
                width="186">
                    <template slot-scope="scope">
                        <i class="el-icon-office-building"></i>
                        <span style="margin-left: 5px;margin-right:5px" @click="building(scope.row)">{{scope.row.edit}}</span>
                        <i class="el-icon-edit"></i>
                        <span style="margin-left: 5px;margin-right:5px" @click="edit(scope.row)">编辑</span>
                        <i class="el-icon-delete"></i>
                        <span style="margin-left: 5px;margin-right:5px" @click="del(scope.row.date)">删除</span>
                    </template>
                </el-table-column>
                
            </el-table>
            <!-- 分页器 -->
            <div class="block">
                <el-pagination
                background
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page.sync="currentPage2"
                :page-sizes="[10, 20, 30, 40]"
                :page-size="50"
                layout=" prev, pager, next, sizes,jumper"
                :total="totalpage">
                </el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    data(){
        return{
            options: [{
            value: '选项1',
            label: '万达文旅城'
            }, {
            value: '选项2',
            label: '碧桂园'
            }, {
            value: '选项3',
            label: '万象城'
            }, {
            value: '选项4',
            label: '龙须面'
            }, {
            value: '选项5',
            label: '北京烤鸭'
            }],
            value2: [],
            // tableData: [
            //     {
            //         date: '1',
            //         Belongingcommunity: '万达文旅城',
            //         Garagename: '地下车库',
            //         ParkingArea:'A区',
            //         ParkingNumber:'A-101',
            //         Parkingspacestatus:'未使用',
            //         Parkingspacearea:'12㎡',
            //         BuildingUsage:'',
            //         edit:'绑定业主',
            //         del:'编辑',
            //         opertes:'删除'
            //     }, 
            //     {
            //         date: '2',
            //         Belongingcommunity: '万达文旅城',
            //         Garagename: '地下车库',
            //         ParkingArea:'A区',
            //         ParkingNumber:'A-101',
            //         Parkingspacestatus:'未使用',
            //         Parkingspacearea:'12㎡',
            //         BuildingUsage:'',
            //         edit:'绑定业主',
            //         del:'编辑',
            //         opertes:'删除'
            //     }, 
            //     {
            //         date: '3',
            //         Belongingcommunity: '万达文旅城',
            //         Garagename: '地下车库',
            //         ParkingArea:'A区',
            //         ParkingNumber:'A-101',
            //         Parkingspacestatus:'未使用',
            //         Parkingspacearea:'12㎡',
            //         BuildingUsage:'',
            //         edit:'绑定业主',
            //         del:'编辑',
            //         opertes:'删除'
            //     }, 
            //     {
            //         date: '4',
            //         Belongingcommunity: '万达文旅城',
            //         Garagename: '地下车库',
            //         ParkingArea:'A区',
            //         ParkingNumber:'A-101',
            //         Parkingspacestatus:'未使用',
            //         Parkingspacearea:'12㎡',
            //         BuildingUsage:'',
            //         edit:'绑定业主',
            //         del:'编辑',
            //         opertes:'删除'
            //     }, 
            //     {
            //         date: '5',
            //         Belongingcommunity: '万达文旅城',
            //         Garagename: '地下车库',
            //         ParkingArea:'A区',
            //         ParkingNumber:'A-101',
            //         Parkingspacestatus:'未使用',
            //         Parkingspacearea:'12㎡',
            //         BuildingUsage:'',
            //         edit:'绑定业主',
            //         del:'编辑',
            //         opertes:'删除'
            //     }, 
            //     {
            //         date: '5',
            //         Belongingcommunity: '万达文旅城',
            //         Garagename: '地下车库',
            //         ParkingArea:'A区',
            //         ParkingNumber:'A-101',
            //         Parkingspacestatus:'未使用',
            //         Parkingspacearea:'12㎡',
            //         BuildingUsage:'',
            //         edit:'绑定业主',
            //         del:'编辑',
            //         opertes:'删除'
            //     }, 
            //     {
            //         date: '5',
            //         Belongingcommunity: '万达文旅城',
            //         Garagename: '地下车库',
            //         ParkingArea:'A区',
            //         ParkingNumber:'A-101',
            //         Parkingspacestatus:'未使用',
            //         Parkingspacearea:'12㎡',
            //         BuildingUsage:'',
            //         edit:'绑定业主',
            //         del:'编辑',
            //         opertes:'删除'
            //     }, 
            //     {
            //         date: '5',
            //         Belongingcommunity: '万达文旅城',
            //         Garagename: '地下车库',
            //         ParkingArea:'A区',
            //         ParkingNumber:'A-101',
            //         Parkingspacestatus:'未使用',
            //         Parkingspacearea:'12㎡',
            //         BuildingUsage:'',
            //         edit:'绑定业主',
            //         del:'编辑',
            //         opertes:'删除'
            //     }, 

            // ],//数据表格数据
            tableData:[],   //数据表格
            currentPage2: 1,//分页器数据
            datalists:[],    //数据总列表
            pagelimit:10,   //每页显示多少条   
            totalpage:300,  //总页数
        }
    },
    watch:{
        currentPage2:{
            handler(val,oldval){
                console.log((val-1)*this.pagelimit,val*this.pagelimit)
                this.tableData=this.datalists.slice((val-1)*this.pagelimit,val*this.pagelimit)
            },
        }, 
        pagelimit:{
            handler(val,oldval){
                console.log(val,oldval)
                this.tableData=this.datalists.slice((this.currentPage2-1)*val,val*this.currentPage2)
            }
        }
    },
    mounted(){
        // this.$store.dispatch('selectData','/community')
        this.$axios.get('http://127.0.0.1/garaglist').then(res=>{
            console.log(res.data)
            this.datalists=res.data
            this.tableData=res.data.slice(0,10)
            this.totalpage=res.data.length
        }).catch(err=>{
            console.log(err)
        })
    },
    methods:{
        select(){
            console.log("查询")
        },
        reasert(){
            console.log("重置")
        },
        appends(){
            console.log("批量添加")
        },
        append(){
            console.log("添加")
            this.$router.push('/about/Addparkingspace')
        },
        // 分页器打印
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
            this.pagelimit=val
        },
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`);
        },
        // 数据表格中楼宇管理、编辑和删除
        building(data){
            console.log("楼宇管理",data)
            if(data.Housingstatus=="未使用"){
                this.$router.push({
                    path:'/about/BingdingOwner',
                    query:{
                        data,
                        dataStore:'parkinglot'
                    }
                })
            }else{
                this.$confirm('此操作将解除业主绑定, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.$axios.post('http://127.0.0.1/ownercontact',{
                        date:data.date,
                        dataStore:'parkinglot'
                    }).then(res=>{
                        this.$axios.get('http://127.0.0.1/garaglist').then(res=>{
                            console.log(res.data)
                            this.datalists=res.data
                            this.tableData=res.data.slice(0,10)
                            this.totalpage=res.data.length
                        }).catch(err=>{
                            console.log(err)
                        })
                    }).catch(err=>{
                        console.log(err)
                    })
                    this.$message({
                        type: 'success',
                        message: '解除绑定成功!'
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消操作'
                    });          
                });
            }
        },
        // 编辑
        edit(data){
            console.log('编辑',data)
            this.$router.push({
                path:'/about/Addparkingspace',
                query:{
                    data
                }
            })
        },
        // 删除
        del(i){
            console.log(i)
            this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
                }).then(() => {
                    console.log('删除')
                    this.$axios.post('http://127.0.0.1/garaglistdelete',{
                        date:i
                    }).then(res=>{
                        console.log(res.data)
                        this.datalists=res.data
                        this.tableData=res.data.slice((this.currentPage2-1)*this.pagelimit,this.pagelimit*this.currentPage2)
                        this.totalpage=res.data.length
                        this.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                    }).catch(err=>{
                        console.log(err)
                    })  
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });          
                });
        }
    }
};
</script>

<style lang="scss" scoped>
    // 数据列表
    .datalists{
        width: 1260px;
        padding: 0 20px;
        margin-top: 10px;
        background-color: #fff;
        border: 1px solid rgba(233, 233, 233, 1);
        position: relative;
        box-sizing: border-box;
        // 数据列表名字名称
        .datalistsname{
            margin-top: 40px;
            width: 57px;
            height: 18px;
            line-height: 18px;
            color: #666666;
            font-size: 14px;
        }
        // 添加数据按钮
        .append,.appends{
            width: 80px;
            height: 35px;
            position: absolute;
            right: 20px;
            top: 23px;
            display: flex;
            align-items: center;
            justify-content: center;
            background-color: #0079fe !important;
            .el-icon-plus,.el-icon-folder-add{
                font-size: 16px;
                margin-right: 5px;
                font-weight: 700;
            }
        }
        .append:hover,.appends:hover{
            background-color: #66b1ff !important;
            color: #fff !important;
        }
        .appends{
            position: absolute;
            padding: 0 2px;
            right: 120px;
            top: 23px;
        }
        // 数据表格
        .datatable{
            margin-top: 20px;
            ::v-deep .has-gutter th{
                height: 45px !important;
                background-color: #f5f5f5;
                box-sizing: border-box;
                padding: 0 !important;
                font-size: 14px;
                color: #666666;
                font-family: '微软雅黑 Bold', '微软雅黑 Regular', '微软雅黑' !important;
            }
            ::v-deep .el-table__row td{
                height: 50px !important;
                padding: 0 !important;
            }
            ::v-deep .el-table--enable-row-hover .el-table__body tr:hover>td.el-table__cell {
                background-color: #f9f9f9;
            }
            ::v-deep .el-table__row .el-table__cell:nth-child(2){
                // text-align: center !important;
                color: #333 !important;
            }
            ::v-deep .el-table__row .el-table__cell:nth-child(1){
                color: #333 !important;
                text-align: center;
            }
            ::v-deep .el-table__row .el-table__cell:nth-child(4){
                color: #333 !important;
            }
            ::v-deep .el-table__row .el-table__cell:nth-last-child(1){
                text-align: center;
                color: #0079fe;
                // cursor: pointer;
            }
            ::v-deep .el-table__row .el-table__cell:nth-last-child(1) span:hover{
                cursor: pointer;
                text-decoration: underline !important;
                // color: #4a4a4a;
            }
            ::v-deep .el-table__row .el-table__cell{
                color: #666666;
                font-size: 12px;
            }
            ::v-deep .el-table__row:hover{
                background-color: inherit !important;
            }
            // 分页
            .block{
                display: flex;
                justify-content: end;
                ::v-deep .el-pagination__sizes{
                    margin-left: 10px;
                    width: 80px;
                    height: 35px;
                    line-height: 35px;
                }
                ::v-deep .btn-prev,::v-deep .el-pager li,::v-deep .btn-next{
                    width: 35px;
                    height: 35px;
                    line-height: 35px;
                    background-color: #fff;
                    border: 1px solid rgba(228, 228, 228, 1);
                }
                ::v-deep .el-pager .active{
                    background-color: #0079fe !important;
                }
                ::v-deep .el-pager .active:hover{
                    color: #fff !important;
                    border: 1px solid rgb(228, 228, 228) !important;
                    box-sizing: border-box;
                }
                ::v-deep .el-pager li:hover,::v-deep .btn-prev:hover,::v-deep .btn-next:hover,::v-deep  .el-pagination__sizes .el-input .el-input__inner:hover {
                    border-color: #0079fe;
                    color: #0079fe;
                }
                ::v-deep .el-input--mini .el-input__inner,::v-deep .el-input--mini .el-input__icon {
                    height: 35px;
                    line-height: 35px;
                }
                ::v-deep .el-pagination .el-select .el-input {
                    width: 86px;
                    margin: 0 5px;
                }
                ::v-deep .el-pagination__jump{
                    height: 35px;
                    line-height: 35px;
                }
                ::v-deep .el-input__inner:focus {
                    border-color: rgb(228, 228, 228) !important;
                    outline: 0;
                }
            }
        }
    }
</style>    